package com.wei.type2;

/**
 * 测试类
 *
 * @author :sunwei
 * @description:
 * @date create in 23:17  2021/7/28
 */
public class TestMain {
    
    /**
     * 1.增加提交的任务数为4000,将有机会触发拒绝策略.
     * 2.任务数少(40)的大部分情况下不会触发拒绝策略,会等到shutdown
     * @param args
     */
    public static void main(String[] args) {
        SimpleThreadPool pool = new SimpleThreadPool(8,20,SimpleThreadPool.DEFAULT_DISCARD_POLICY);
        for (int i = 0; i < 40; i++) {
            int finalI = i;
            pool.submit(() -> {
                System.out.println(Thread.currentThread().getName() + " server for " + finalI);
            });
    
            try {
                //让任务有机会被notify,而不是一直加任务到队列中
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            pool.shutdown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        pool.submit(()->{
            System.out.println("resubmit...");
        });
    
    }
}
